Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

Plan to fix null value handling in Kibana connector config

  • Update SanitizedValue() function to remove null entries from top-level fields
  • Update SanitizedValue() to recursively remove null entries from nested maps
  • Add unit tests for null value removal in config_value_test.go
  • Add acceptance test step to TestAccResourceKibanaConnectorCasesWebhook to test null headers
  • Run unit tests to verify changes
  • Run linting and documentation generation
  • Run code review and address feedback
  • Run security scan with codeql_checker
  • Address PR review feedback: refactor if/else block to use explicit continue statements
  • Add CHANGELOG.md entry
  • Update CHANGELOG.md to be consistent with other entries

Summary

This PR fixes a bug where the elasticstack_kibana_action_connector resource fails with "Provider produced inconsistent result after apply" when the config JSON includes null values (e.g., headers = null).

Root Cause

When users provide headers = null (or any other null field) in the connector config JSON, the Terraform provider would:

  1. Accept the config with null values during plan
  2. Store the config without null values after apply (Kibana API doesn't return null fields)
  3. Compare the two configs and detect a difference, causing an "inconsistent result" error

Solution

Updated the SanitizedValue() function to recursively remove all null values from the config map before marshaling it back to JSON. This ensures that null values are removed from both the planned and actual state, preventing state mismatches.

Changes Made

  1. Code Changes:

    • Added removeNulls() helper function that recursively removes null values from maps
    • Updated SanitizedValue() to call removeNulls() after removing the connector type ID key
    • Fixed regex escaping consistency in acceptance tests
    • Refactored removeNulls() to use explicit continue statements for better code clarity
  2. Tests Added:

    • 5 new unit test cases covering null value removal scenarios:
      • Top-level null values
      • Nested null values
      • Mixed null values (top-level and nested)
      • All-null config resulting in empty object
      • Null values combined with connector type ID removal
    • New acceptance test step with headers = null to verify end-to-end functionality
  3. Documentation:

    • Added entry to CHANGELOG.md under Unreleased section with PR number
  4. All Tests Pass:

    • All existing unit tests continue to pass
    • New unit tests for null removal pass
    • Linting and documentation generation successful
    • No security vulnerabilities detected

Security Summary

No security vulnerabilities were introduced or discovered during this change.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] elasticstack_kibana_action_connector .webhook fails with "inconsistent result after apply" when headers = null is present</issue_title>
<issue_description>Describe the bug
The elasticstack_kibana_action_connector resource with connector_type_id = ".webhook" fails during terraform apply when the config JSON includes headers = null. The provider errors with "Provider produced inconsistent result after apply," indicating a bug related to handling of null values in the config.

To Reproduce
Steps to reproduce the behavior:

  1. TF configuration used:
resource "elasticstack_kibana_action_connector" "webhook" {
  connector_id      = "webhook-connector-id"
  connector_type_id = ".webhook"
  name              = "Hello webhook connector. (Terraform managed)"
  space_id          = "foo"

  config = jsonencode({
    authType = "webhook-authentication-basic"
    hasAuth  = true
    headers  = null
    method   = "post"
    url      = "https://foo.com/webhook"
  })

  secrets = (sensitive value)
}
  1. TF operations to execute to get the error: terraform apply
  2. See the error in the output:
Error: Provider produced inconsistent result after apply

When applying changes to elasticstack_kibana_action_connector.webhook, provider
"provider[\"registry.terraform.io/elastic/elasticstack\"].foo" produced an unexpected new value: .config was
cty.StringVal("{\"authType\":\"webhook-authentication-basic\",\"hasAuth\":true,\"headers\":null,\"method\":\"post\",\"url\":\"https://foo.com/webhook\"}"), but now
cty.StringVal("{\"__tf_provider_connector_type_id\":\".webhook\",\"authType\":\"webhook-authentication-basic\",\"hasAuth\":true,\"method\":\"post\",\"url\":\"https://foo.com/webhook\"}").

This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected behaviour
Terraform apply should succeed without errors. The provider should handle null values in config JSON gracefully, either by normalising or safely ignoring them, without triggering inconsistent state or apply failure.[1]

Debug output
TF_LOG=trace logs confirm the provider mishandles null in the headers field, causing state mismatches after apply. All sensitive credentials are redacted.

Screenshots
N/A

Versions (please complete the following information):

  • Terraform Version: 1.13.0
  • Provider version: elastic/elasticstack >= 0.12.2
  • Elasticsearch Version: 8.19

Additional context
Workaround: Remove the headers = null setting from the .webhook connector config or omit it entirely if not required, which prevents this error and allows apply to succeed. This bug relates to provider's null value handling in JSON config and should be fixed to accept or reject null cleanly.[2]</issue_description>

<agent_instructions>Update the existing SanitizedValue function in internal/kibana/connectors/config_value.go` to remove null entries from the sanitised map.

The new code should remove nulls from both top level fields in the unsanitised map, along with nulls from any nested maps.

Add unit tests covering this new functionality.
Add a step to the existing TestAccResourceKibanaConnectorCasesWebhook acceptance test covering this as well. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 8, 2025 21:03
Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix elasticstack_kibana_action_connector error on null headers Fix null value handling in Kibana connector config causing inconsistent apply state Dec 8, 2025
Copilot AI requested a review from tobio December 8, 2025 21:11
Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
Copilot AI requested a review from tobio December 8, 2025 22:11
@tobio tobio marked this pull request as ready for review December 8, 2025 22:53
Copilot AI review requested due to automatic review settings December 8, 2025 22:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where the elasticstack_kibana_action_connector resource fails with "Provider produced inconsistent result after apply" when null values (e.g., headers = null) are present in the connector configuration JSON. The fix ensures that null values are recursively removed from the configuration before state comparison, preventing state mismatches.

Key Changes:

  • Added recursive null value removal to the SanitizedValue() function via a new removeNulls() helper
  • Added comprehensive unit tests covering various null value scenarios
  • Added acceptance test steps to verify null value handling in real-world scenarios

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/kibana/connectors/config_value.go Added removeNulls() helper function and integrated it into SanitizedValue() to recursively remove null values from configuration maps
internal/kibana/connectors/config_value_test.go Added 5 new unit test cases covering null value removal in top-level, nested, mixed, all-null, and combined scenarios
internal/kibana/connectors/acc_test.go Added new acceptance test step with null headers and fixed regex escaping for consistency
internal/kibana/connectors/testdata/TestAccResourceKibanaConnectorCasesWebhook/with_predefined_connector_id/null_headers/connector.tf New test configuration file with headers = null for predefined connector ID test case
internal/kibana/connectors/testdata/TestAccResourceKibanaConnectorCasesWebhook/with_empty_connector_id/null_headers/connector.tf New test configuration file with headers = null for empty connector ID test case

@tobio tobio requested review from dimuon and nick-benoit and removed request for tobio December 9, 2025 05:56
@tobio
Copy link
Member

tobio commented Dec 9, 2025

@copilot add an entry to CHANGELOG.md for this PR

Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 9, 2025

@copilot add an entry to CHANGELOG.md for this PR

Done in 69ff68b. Added CHANGELOG entry under the Unreleased section describing the fix for null value handling in elasticstack_kibana_action_connector.

Copilot AI requested a review from tobio December 9, 2025 07:52
CHANGELOG.md Outdated

### Changes

- Fix `elasticstack_kibana_action_connector` failing with "inconsistent result after apply" when config contains null values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Be consistent with the other changelog entries.

Suggested change
- Fix `elasticstack_kibana_action_connector` failing with "inconsistent result after apply" when config contains null values
- Fix `elasticstack_kibana_action_connector` failing with "inconsistent result after apply" when config contains null values ([#1524](https://github.com/elastic/terraform-provider-elasticstack/pull/1524))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 36df21d. Updated the CHANGELOG entry to include the PR number reference for consistency with other entries.

Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
Copilot AI requested a review from tobio December 9, 2025 09:49
@tobio tobio merged commit 6f2ec51 into main Dec 10, 2025
54 checks passed
@tobio tobio deleted the copilot/fix-webhook-connector-bug branch December 10, 2025 01:39
tobio added a commit that referenced this pull request Dec 10, 2025
* origin/main:
  Fixup changelog
  Bump release disk size
  Prepare 0.13.0 release (#1532)
  Fix null value handling in Kibana connector config causing inconsistent apply state (#1524)
  Add Security List Data Stream Resource (#1525)
  chore(deps): update golang:1.25.5 docker digest to 0ece421 (#1531)
  Fleet agent policy host name format field (#1521)
  chore(deps): update kibana-openapi-spec digest to 6647f81 (#1528)
  chore(deps): update kibana-openapi-spec digest to bd3d07c (#1519)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] elasticstack_kibana_action_connector .webhook fails with "inconsistent result after apply" when headers = null is present

3 participants